package com.example.print.other;

import android.app.ProgressDialog;
import android.content.Context;
import android.os.AsyncTask;
import android.util.Log;
import android.widget.Toast;

import com.example.print.R;

public class BaseInitTask extends AsyncTask<String, Integer, Boolean> {
    protected CustomeProgressDialog mypDialog;
    protected Context mContxt;

    public BaseInitTask(Context act) {
        mContxt = act;
    }

    @Override
    protected void onCancelled(Boolean aBoolean) {
        super.onCancelled(aBoolean);
        dismissDialog();
        Log.i("BaseInitTask", "onCancelled()");
    }

    public void dismissDialog() {
        if (mypDialog != null) {
            mypDialog.cancel();
        }
    }

    @Override
    protected Boolean doInBackground(String... params) {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    protected void onPostExecute(Boolean result) {
        super.onPostExecute(result);
        mypDialog.cancel();
        if (!result) {
            Toast.makeText(mContxt, R.string.fingerprint_msg_init_fail, Toast.LENGTH_LONG).show();
        }
    }

    @Override
    protected void onPreExecute() {
        // TODO Auto-generated method stub
        super.onPreExecute();

        if (mContxt != null) {
            mypDialog = new CustomeProgressDialog(mContxt);
            mypDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
            mypDialog.setMessage(mContxt.getString(R.string.app_msg_init));
            mypDialog.setCanceledOnTouchOutside(false);
            mypDialog.show();
        }
    }
}
